


import os
"""插入os模块"""

all_size = 0

"""全局变量"""

def dir_size(dir_name):
    global all_size
    file_list = os.listdir(dir_name)   # 获取目录内的文件列表
    print(file_list)
    for file in file_list:
        file_path = os.path.join(dir_name, file)
        print(dir_name)
        if os.path.isfile(file_path):   # 如果是文件
            size = os.path.getsize(file_path)
            print(size)
            all_size += size
            print(file_path)
        else:
            dir_size(file_path)
dir_size('/Users/fangruiqian/Desktop/未命名文件夹')

print(all_size)


